// Write your cade below:
function main() {
    var readlineSync=require('readline-sync')
    let randomNum=getRandom();
    console.log(randomNum);
    let inputs=readlineSync.question('\nPlease enter four digits:\n');
    let result=check(inputs,randomNum);  
    for(let i=0;;i++){
    if(result!="4A0B"){
        console.log(result);
        inputs=readlineSync.question('\nPlease enter four digits:\n');
        result=check(inputs,randomNum);
    }
    else{
        console.log("nice!!");
        break;
    }
}
    return result;
};

function getRandom(){
    let randomNum="";
    for(let i=0;i<4;i++){
        randomNum+=Math.floor(Math.random()*10);
    }
    return randomNum;
};

function check(inputs,randomNum){
    let a=0;
    let b=0;
    inputs=inputs+"";
    randomNum=randomNum+"";
    for(let i=0;i<inputs.length;i++){
        if(randomNum.indexOf(inputs[i])!=-1){
            if(inputs[i]==randomNum[i]){
                a++;
            }
            else{
                b++;
            }
        }
    }
    let result=a+"A"+b+"B";
    return result;
}





exports.main=main;
exports.getRandom=getRandom;
exports.check=check;